#ifndef DIALOGLOOP_H
#define DIALOGLOOP_H

#include <QDialog>
#include <QTreeWidgetItem>
#include "frequencelist.h"
#include "programlist.h"


namespace Ui {
class DialogLoop;
}

class DialogLoop : public QDialog
{
    Q_OBJECT

public:
    explicit DialogLoop(QWidget *parent = 0);
    ~DialogLoop();

    void setProgramList(const tv::FrequenceList& freqList, const tv::ProgramList& programList);

    void setLoopList(const tv::ProgramList& programList);

    tv::ProgramList& getLoopList();

private slots:
    void on_pushButtonAdd_clicked();

    void on_pushButtonDelete_clicked();

    void on_pushButtonAddAll_clicked();

    void on_pushButtonDeleteAll_clicked();

    void on_pushButtonImport_clicked();

    void on_pushButtonExport_clicked();


private:
    enum Role
    {
        kNumRole = Qt::UserRole + 1
    };

    void refreshTable();

    void setProgram(int row, const tv::Program& program);

    void appendProgram(const tv::Program& program);

    void refreshProgramTree();
    QTreeWidgetItem* findFreqItem(const std::string& num);

    void addPrograms(const std::string& freqNum);

private:
    Ui::DialogLoop *ui;


private:
    tv::FrequenceList   m_freqList;
    tv::ProgramList     m_programList;
    tv::ProgramList     m_loopList;

};

#endif // DIALOGLOOP_H
